{template 'web/'.$cfg['floder'].'/base_menu'}
<div class="top_tab">
    <a href="{php echo $this->createWebUrl('staff')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">管理员工</a>
    <a href="{php echo $this->createWebUrl('staff',array('op'=>'post'))}" class="layui-btn {if $operation != 'post'}layui-btn-primary{/if}">添加员工</a>
    <div class="secrchinput">
        <button><i class="fa fa-search"></i></button>
        <input type="text" id="txtTopupSeachStr" placeholder="输入">
    </div>
</div>
{if $operation == 'post'}
<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{php echo $id}" />
        <div class="panelbox-head">{if !$id}添加新员工{else}编辑【{$item['realname']}】{/if}</div>
        <div class="panelbox-body">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="开启"  {if $item['status']}checked{/if} />
                    <input type="radio" name="status" value="0" title="禁用" {if !$item['status']}checked{/if} />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input type="text" name="useracount" maxlength="10" class="layui-input" value="{$item['useracount']}" {if $id}disabled{/if}/>
                    <div class="help-block">用于登录使用，不能以0开头。如“A01”。注意：提交不可更改</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属店铺</label>
                <div class="layui-input-block form-inline">
                    <select name="pcate" class="layui-input">
                        <option value="0">请选择</option>
                        {loop $list $row}
                        <option value="{$row['id']}" {if $row['id']==$item['pcate']} selected{/if}>{$row['companyname']}</option>
                        {/loop}
                    </select>
                    <div class="help-block">此内容可用于多门店，或者是不同地区收款时，作为统计时使用</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色权限</label>
                <div class="layui-input-block">
                    <input type="radio" name="permission" value="1" title="收银员" {if $item['permission'] == 1 || empty($item['permission'])}checked{/if} />
                    <input type="radio" name="permission" value="2" title="财务"  {if $item['permission'] == 2}checked{/if} />
                    <input type="radio" name="permission" value="3" title="店长" {if $item['permission'] == 3}checked{/if} />
                    <div class="help-block">【收银员】除了收银外，其他不能操作；【财务】除继承上级功能外，可以导出各类数据；【店长】出上述功能外，可管理人员</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">其他权限</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isdiscount" {if $item['isdiscount']}checked{/if} title="修改商品价格"/>
                    <div class="help-block">此项仅针对【收银员】资质的人员，上述功能只针对【前台收银】</div>
                </div>
            </div>
            {if $_W['isfounder'] || $_W['role']=="manager"}
            <div class="layui-form-item">
                <label class="layui-form-label">对应后台账号</label>
                <div class="layui-input-block">
                    <select name="docking" class="layui-input">
                        <option value="0">请选择</option>
                        {loop $users $row}
                        <option value="{$row['uid']}" {if $row['uid']==$item['docking']}selected{/if}>{$row['username']}</option>
                        {/loop}
                    </select>
                    <div class="help-block">仅为管理员可见。用于后台登陆管理，免去后台登陆时二次登陆的麻烦。</div>
                </div>
            </div>
            {else}
            <input type="hidden" name="docking" value="{$item['docking']}">
            {/if}
            <div class="layui-form-item">
                <label class="layui-form-label">openid</label>
                <div class="layui-input-block">
                    <input type="text" name="openid" class="layui-input" value="{$item['openid']}" />
                    <div class="help-block">请在粉丝列表中查找-<a href="./index.php?c=mc&a=fans" target="_blank">粉丝列表</a></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-block">
                    {php echo tpl_form_field_image('headimg', $item['headimg']);}
                    <div class="help-block">100*100px</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="realname" class="layui-input" value="{$item['realname']}" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input type="text" name="mobile" class="layui-input" value="{$item['mobile']}" autocomplete="off" />
                    <div class="help-block">无具体作用，仅为记录</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">短密码</label>
                <div class="layui-input-block">
                    <input type="text" name="spassword" class="layui-input" value="{$item['spassword']}" autocomplete="off"/>
                    <div class="help-block">请输入4位数字，用于移动端登陆使用。第一位不能是0。</div>
                </div>
            </div>
            {if empty($id)}
            <div class="layui-form-item">
                <label class="layui-form-label">输入密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" class="layui-input" autocomplete="off"/>
                    <div class="help-block">不少于6位英文、数字、符号</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password2" class="layui-input" autocomplete="off"/>
                    <div class="help-block"></div>
                </div>
            </div>

            {else}
            <div class="layui-form-item">
                <label class="layui-form-label">修改密码</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-primary" onclick="changepassword()">修改密码</button>
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">设备号</label>
                <div class="layui-input-block">
                    <input type="text" name="imei" class="layui-input" value="{$item['imei']}" autocomplete="off"/>
                    <div class="help-block">添加新设备：清空【设备号】的内容，再将【允许移动端】设置为【禁用】，即可在移动端增加。待添加后，再将【允许移动端】设置成【开启】即可使用。</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">允许移动端</label>
                <div class="layui-input-block">
                    <input type="radio" name="isimei" value="1" title="开启"  {if $item['isimei']}checked{/if} />
                    <input type="radio" name="isimei" value="0" title="禁用" {if !$item['isimei']}checked{/if} />
                    <div class="help-block">添加新设备：清空【设备号】的内容，再将【允许移动端】设置为【禁用】，即可在移动端增加。待添加后，再将【允许移动端】设置成【开启】即可使用。</div>
                </div>
            </div>
            {/if}
        </div>
        <div class="panelbox-foot">
            <input type="hidden" name="token" value="{$_W['token']}" />
            <input class="layui-btn" type="submit" lay-submit="" name="submit" lay-filter="submitbtn" value="提交">
        </div>
    </form>
</div>
{else}
<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <div class="panelbox-head"> 管理员工 </div>
        <div class="panelbox-body">
            <div class="layui-form">
                <table class="layui-table">
                    <colgroup>
                        <col width="50">
                        <col width="150">
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th style="width:60px"><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                        <th>工号</th>
                        <th>姓名</th>
                        <th>电话</th>
                        <th>所属店铺</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $row}
                    <tr>
                        <td><input type="checkbox" name="" lay-skin="primary"></td>
                        <td>{$row['useracount']}</td>
                        <td>{$row['realname']}</td>
                        <td>{$row['mobile']}</td>
                        <td><a href="{php echo $this->createWebUrl('staff',array('groupid'=>$row['pcate']))}" class="tblink">{php echo $groupary[$row['pcate']]}</a></td>
                        <td>{if $row['status']}<span class="label label-info">正常</span>{else}<span class="label label-default">未开通</span>{/if}</td>
                        <td class="text-right"><a href="{php echo $this->createWebUrl('staff',array('op'=>'post','id'=>$row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a> <a href="javascript:deleteContent('{php echo $this->createWebUrl('staff',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="panelbox-foot">  </div>
    </form>
</div>
{/if}

<script language="javascript">
    layui.use(['layer', 'laypage', 'element','form'], function(){
        var layer = layui.layer
                ,laypage = layui.laypage
                ,element = layui.element
                ,form = layui.form;
        form.render();
        form.on('submit(submitbtn)', function(data){

            return true;
        });
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });
    function changepassword(){
        layer.prompt({title: '修改密码', formType: 1}, function(pass, index){
            if(pass.length<6){
                layer.msg('密码不能少于6位');
                return;
            }
            layer.close(index);
            layer.prompt({title:'确认刚才输入的密码',formType:1}, function(text, index){
                layer.close(index);
                if(pass!=text){
                    layer.msg('两次输入的密码不一样，请重新输入',{time:2000}, function(){
                        changepassword();
                    });
                    return;
                }
                var index2=layer.load(1, {shade: [0.5,'#fff']});
                $.post("{php echo $this->createWebUrl('staff',array('op'=>'changepass'))}",{"id":"{$id}","pass":pass},function(data){
                    layer.close(index2);
                    if(!data.success){
                        layer.msg(data.msg,{icon:1,time:2000});
                        return;
                    }
                    layer.msg('密码修改成功',{icon:1,time:2000});
                },'json');
            });
        });
    }
    function deleteContent(url){
        layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
            location.href=url;
        });
    }
</script>